"""
发送post请求
    url,请求头，请求体
"""
import requests


# 请求体数据

class YouDao:
    def __init__(self, word):
        self.url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
        self.h = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
        }
        self.data = {
            'i': word,
            'from': 'AUTO',
            'to': 'AUTO',
            'smartresult': 'dict',
            'client': 'fanyideskweb',
            'salt': '16064422328461',
            'sign': 'ad44488648b3c36657e3cf9cb73208d4',
            'lts': '1606442232846',
            'bv': 'f7d97c24a497388db1420108e6c3537b',
            'doctype': 'json',
            'version': '2.1',
            'keyfrom': 'fanyi.web',
            'action': 'FY_BY_REALTlME',
        }

    def fan_yi(self):
        response = requests.post(self.url, headers=self.h, data=self.data)
        return response.content.decode()


fan1 = YouDao('加油')
print(fan1.fan_yi())
